package com.stu.service.impl;

import com.github.pagehelper.Page;
import com.stu.bean.Goods;
import com.stu.bean.GoodsExample;
import com.stu.mapper.GoodsMapper;
import com.stu.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    public Page<Goods> selectAllGoods(Goods goods) {
        return goodsMapper.selectAllGoods(goods);
    }

    public int delGoods(int gid) {
        return goodsMapper.deleteByPrimaryKey(gid);
    }

    public Goods selectGoods(int gid) {
        return goodsMapper.selectByPrimaryKey(gid);
    }

    public int updateGoods(Goods goods) {
        return goodsMapper.updateByPrimaryKeySelective(goods);
    }

    public Goods insertSp(Goods goods) {
        Goods goods1 = null;
        int g = goodsMapper.insertSelective(goods);
        if(g ==1){
            goods1 = goodsMapper.selectGoodsByUsername(goods.getGimg());
        }
        return goods1;
    }

    public int selectGoodsTotal() {
        GoodsExample goodsExample=new GoodsExample();
        return goodsMapper.selectByExample(goodsExample).size();
    }
}
